package date;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;

public class DateApp {

	public static void main(String[] args) {

		Date zeroMillsDate = new Date(0L);
		Date yzFirstRecordDate = new Date(1301387334000L);
		Date now = new Date();

		System.out.println("zeroMillsDate: " + zeroMillsDate); // Thu Jan 01 08:00:00 CST 1970
		System.out.println("yzFirstRecordDate: " + yzFirstRecordDate); // Tue Mar 29 16:28:54 CST

		System.out.println(yzFirstRecordDate.toString());
		System.out.println(yzFirstRecordDate.toLocaleString());
		System.out.println(yzFirstRecordDate.toGMTString());

		System.out.println();

		SimpleDateFormat sdf_local = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.CHINA);
		SimpleDateFormat sdf_gmt = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.ENGLISH); // The same ?!
		try {
			System.out.println(sdf_local.format(now));
			System.out.println(sdf_local.parse("2011-03-29 16:28:54").getTime() / 1000);
			System.out.println(sdf_local.parse("1970-01-01 00:00:00").getTime() / 1000);
			System.out.println(sdf_gmt.parse("1970-01-01 00:00:00").getTime() / 1000);
		} catch (ParseException e) {
			e.printStackTrace();
		}

		System.out.println();

		long timezoneOffsetByDate = now.getTimezoneOffset();
		Calendar cal = Calendar.getInstance();
		int timezoneOffsetByCal = cal.get(Calendar.ZONE_OFFSET) + cal.get(Calendar.DST_OFFSET);
		System.out.println(timezoneOffsetByDate);
		System.out.println(timezoneOffsetByCal / 60 / 60 / 1000);
		System.out.println(timezoneOffsetByCal / timezoneOffsetByDate);
												// 2011
	}
}
